/**
 * 
 */
package matrices;

import Jama.Matrix;
import Jama.util.Maths;

/**
 * @author usuario_local
 *
 */
public class PruebasLLoyd {

	
	
	public static double distancia(Matrix x, Matrix c)
	{
		double d1= x.get(0, 0)-x.get(0, 1);
		double d2= c.get(0, 0)-c.get(0, 1);
		d1 *= d1;
		d2 *= d2;
		double aux = d1+ d2;
		 
		return Math.sqrt(aux);
	}
	
	public static Matrix actualiza(double aprnd, Matrix x , Matrix c)
	{
		return x.minus(c).times(aprnd).plus(c);
		
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) 
	{
		//double array[][] = { {1,2,3,4}, {5,6,7,8}}; 
		double datos[][] = {{1,1},{1,3},{1,5},{2,2},{2,3},{6,3},{6,4},{7,1},{7,3},{7,5}};
		double centro1[][] = {{1,4}};
		double centro2[][] = {{7,4}};
		
		Matrix c1 = new Matrix(centro1);
		Matrix c2 = new Matrix(centro2);
		
		double aprend = 0.1;
		
		for (int i = 0; i< datos.length; i++)
		{
			double xiAux[][] = {{}};
			xiAux[0] = datos[i];
			
			Matrix xi = new Matrix(xiAux);
			
			double valorC1 = distancia(xi, c1);
			double valorC2 = distancia(xi, c1);
			double aux = Math.min(valorC1, valorC2);
			
			if(aux == valorC1)
			{
				c1 = actualiza(aprend,xi, c1 );
			}
			else
			{
				c2 = actualiza(aprend,xi, c2 );
			}
				c1.transpose();
	
		}
		
				
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		Matrix m;
		m = Matrix.random(1, 3);
		double[][] maux = m.getArray();
		for (int i = 0; i< 1; i++)
			for (int j = 0; j<3 ; j++)
			{
			
				System.out.println(maux[i][j]);
			}
		System.out.println( Maths.hypot(1, 2) );
		
		System.out.println(); 
		
		
		
		

	}

}
